﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Defines a clickable image map (&lt;area&gt;).
    /// </summary>
    [Standalone]
    [Serializable]
    public class Area : Element {
        private string _alt;
        private IList<int> _coords;
        private string _href;
        private string _hreflang;
        private string _media;
        private string _name;
        private bool _nohref;
        private ICollection<string> _rel;
        private ShapeChoices? _shape;
        private string _target;
        private string _type;

        /// <summary>
        /// Creates a new instance of an HTML area.
        /// </summary>
        public Area(string alt) {
            _coords = new List<int>();
            _rel = new LinkedList<string>();
            _alt = alt;
        }

        /// <summary>
        /// Gets or sets the text to be displayed if this area cannot be
        /// displayed.
        /// </summary>
        public string Alt {
            get { return _alt; }
            set { _alt = value; }
        }

        /// <summary>
        /// Gets a list of the coordinates of this area.
        /// </summary>
        public IList<int> Coords {
            get { return _coords; }
        }

        /// <summary>
        /// Gets or sets the hyperlink target for this area.
        /// </summary>
        public string Href {
            get { return _href; }
            set { _href = value; }
        }

        /// <summary>
        /// Gets or sets the language of the linked resource.
        /// </summary>
        public string HrefLang {
            get { return _hreflang; }
            set { _hreflang = value; }
        }

        /// <summary>
        /// Gets or sets the media descriptor for the linked resource.
        /// </summary>
        public string Media {
            get { return _media; }
            set { _media = value; }
        }

        /// <summary>
        /// Gets or sets the name of this area.
        /// </summary>
        [Obsolete("Deprecated in HTML5 - use \"ID\" instead.")]
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Determines whether or not there is a link associated with this
        /// area.
        /// </summary>
        [Obsolete("Deprecated in HTML5 - simply omit the \"href\" attribute.")]
        public bool NoHref {
            get { return _nohref; }
            set { _nohref = value; }
        }

        /// <summary>
        /// Gets a collection of all relationships of the linked resource.
        /// </summary>
        public ICollection<string> Rel {
            get { return _rel; }
        }

        /// <summary>
        /// Gets or sets the shape of this area.
        /// </summary>
        public ShapeChoices? Shape {
            get { return _shape; }
            set { _shape = value; }
        }

        /// <summary>
        /// Gets or sets the target that loads the linked resource.
        /// </summary>
        public string Target {
            get { return _target; }
            set { _target = value; }
        }

        /// <summary>
        /// Gets or sets the MIME type of the linked resource.
        /// </summary>
        public string Type {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Writes out the local attributes of this area.
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _alt, "alt");
            AttributeWriter.Write(sb, _coords, "coords", ',');
            AttributeWriter.Write(sb, _href, "href");
            AttributeWriter.Write(sb, _hreflang, "hreflang");
            AttributeWriter.Write(sb, _media, "media");
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _nohref, "nohref");
            AttributeWriter.Write(sb, _rel, "rel", ' ');
            AttributeWriter.Write(sb, _shape, "shape", true);
            AttributeWriter.Write(sb, _target, "target");
            AttributeWriter.Write(sb, _type, "type");
        }
    }
}
